using NLog;
using NLog.Web;

var builder = WebApplication.CreateBuilder(args);
LogManager.Setup().LoadConfigurationFromAppSettings().GetCurrentClassLogger();
LogManager.Configuration.Variables["logdir"] = AppContext.BaseDirectory;

// Add services to the container.

builder.Services.AddControllers();
// Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen();
builder.Services.AddEasyCaching(option =>
{
    option.UseRedis(redisOption =>
    {
        redisOption.DBConfig.Configuration = "192.168.11.79:30843,defaultDatabase=24,password=+Z^(CTxo$7yF!!KdT";
        redisOption.SerializerName = "messagepack";
    }, "redis").WithMessagePack("messagepack");

});

// NLog: Setup NLog for Dependency injection
builder.Logging.ClearProviders();
builder.Logging.SetMinimumLevel(Microsoft.Extensions.Logging.LogLevel.Trace);
builder.Host.UseNLog();

var app = builder.Build();
app.Lifetime.ApplicationStopping.Register(() =>
{
    LogManager.Shutdown();
});

// Configure the HTTP request pipeline.
if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();
